﻿using System;
using Microsoft.Xna.Framework;

namespace Narwhunderful.Aphelia.Framework
{

    public class FrameRateCounter : UpdatableComponent
    {

        int _counter = 0;
        TimeSpan elapsedTime = TimeSpan.Zero;

        int _rate = 0;
        public int Rate
        {
            get
            {
                return _rate;
            }
        }

        public FrameRateCounter(Game game)
            : base(game)
        {
            base.AlwaysNeedsUpdate = true;
        }

        #region IUpdatableComponent

        protected override void InternalUpdate(GameTime gameTime)
        {
            elapsedTime += gameTime.ElapsedGameTime;
            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                _rate = _counter;
                _counter = 0;
            }
        }

        #endregion

        public virtual void IncreaseCounter()
        {
            _counter++;
        }

    }

}
